<html lang="zh_CN">
{% include "common/tree_page_head.html" %}
<script type="text/javascript" src="{{ url_for('static',filename='system/doc/docCenter/mainActivity.js') }}"></script>
<body style="width:100%; height:100%; overflow: hidden;">
<div id="MyDiv" class="easyui-layout" fit="true">
    <div data-options="region:'west',title:'文档目录',split:true" style="width: 300px; overflow: hidden;">
        <form id="main_org_trr" style="display: none;"></form>
        <div class="easyui-layout" fit="true" border="false">
            <div data-options="region:'north',border:false"
                 style="height: 40px;padding: 2px; overflow: hidden;">
                <table>
                    <tr>
                        <td><a href="javascript:void(0);" class="toobar_item" title="新建目录">
                            <img src="{{ url_for('static',filename='common/image/doc/newfolder_g.gif') }}"
                                 id="new_folder_item">
                        </a>
                        </td>
                        <td><a href="javascript:void(0);" class="toobar_item" title="目录属性">
                            <img src="{{ url_for('static',filename='common/image/doc/folder_pro_g.gif') }}"
                                 id="folder_pro_item">
                        </a>
                        </td>
                        <td><a href="javascript:void(0);" class="toobar_item" title="目录权限">
                            <img src="{{ url_for('static',filename='common/image/doc/folder_perm_g.gif') }}"
                                 id="folder_perm_item">
                        </a>
                        </td>
                        <td><a href="javascript:void(0);" class="toobar_item" title="删除目录">
                            <img src="{{ url_for('static',filename='common/image/doc/deletefile_g.gif') }}"
                                 id="deletefile_item">
                        </a>
                        </td>
                        <td><a href="javascript:Jtree.refreshJtree('maintree');" class="toobar_item"
                               title="刷新目录">
                            <img src="{{ url_for('static',filename='common/image/doc/refresh.gif') }}"
                                 id="refresh_folder_item">
                        </a>
                        </td>
                        <td></td>
                    </tr>
                </table>
            </div>
            <div data-options="region:'center',border:false" style="padding: 0px; overflow: hidden;">
                <div id="docfoldertree"
                     style="border-top:1px solid #eee; width:100%;height:100%; overflow:auto;">
                    <ul id="maintree" class="ztree"></ul>
                </div>
            </div>
        </div>
    </div>
    <div data-options="region:'center',title:'文件列表'" style="overflow: hidden;">
        <div style="padding: 5px; width: 100%; position: relative; height: 35px;">
            <div style='float:left; height: 30px; margin-right: 5px;'>
                <button class="layui-btn layui-btn-sm layui-btn-normal layui-btn-disabled" id="upbtn">
                    <i class="layui-icon">&#xe681;</i>&nbsp;上传
                </button>
            </div>
            <div style='float:left; height: 30px; margin-right: 5px;'>
                <button class="layui-btn layui-btn-sm layui-btn-disabled" id="viewbtn">
                    <i class="layui-icon">&#xe705;</i>&nbsp;查看
                </button>
                <button class="layui-btn layui-btn-sm layui-btn-warm layui-btn-disabled" id="editbtn">
                    <i class="layui-icon">&#xe642;</i>&nbsp;编辑
                </button>
                <button class="layui-btn layui-btn-sm layui-btn-disabled" id="downbtn">
                    <i class="layui-icon">&#xe601;</i>&nbsp;下载
                </button>
                <button class="layui-btn layui-btn-sm layui-btn-primary layui-btn-disabled" id="historybtn">
                    <i class="layui-icon">&#xe60e;</i>&nbsp;历史
                </button>
                <button class="layui-btn layui-btn-sm" onclick="doQuery()">
                    <span class='glyphicon glyphicon-repeat'></span>&nbsp;刷新
                </button>
                <button class="layui-btn layui-btn-sm layui-btn-danger layui-btn-disabled" id="deletebtn">
                    <span class='layui-icon layui-icon-delete'></span>&nbsp;删除
                </button>
            </div>
            <div class='input-group input-group-sm' style='float:left; width:280px; height: 30px; margin-left: 5px;'>
                <input type="text" id="query_text" placeholder="快速查询..."
                       class='form-control'>
                <span class='input-group-btn'>
                    <button class='btn btn-default' onclick="doQuery()">
                        <span class='glyphicon glyphicon-search'></span>查询
                    </button>
                </span>
            </div>
        </div>
        <table lay-filter="datalist" class="layui-table"
               lay-data="{height:'full-80', page:true,even:true, id:'datalist'}" id="datalist">
            <thead>
            <tr>
                <th lay-data="{field:'sid',hide:true}"></th>
                <th lay-data="{field:'sfileid',hide:true}"></th>
                <th lay-data="{field:'screatorid',hide:true}"></th>
                <th lay-data="{field:'no',width:60}">序号</th>
                <th lay-data="{field:'sdocname'}">名称</th>
                <th lay-data="{field:'ssize',width:120}">大小</th>
                <th lay-data="{field:'sdocdisplaypath'}">文件路径</th>
                <th lay-data="{field:'screatorname', width:100}">创建人</th>
                <th lay-data="{field:'screatetime', width:160}">创建时间</th>
                <th lay-data="{field:'seditorname', width:100}">修改人</th>
                <th lay-data="{field:'slastwritetime', width:160}">最后修改时间</th>
            </tr>
            </thead>
        </table>
    </div>
</div>
<script type="text/javascript">
    var Jtree = new Jtree();
    var treebody = "maintree";
    Jtree.init(treebody, setting, param);

    function doQuery() {
        let search_text = $("#query_text").val();
        let surl = '/system/doc/docCenter/docDataList?search_text=' + J_u_encode(search_text);
        if (currenttreeID) {
            surl += "&folder=" + J_u_encode(currenttreeID);
        }
        currentRow = {};
        layui.table.reload('datalist', {
            url: surl,
            done: function () {//res, curr, count
                $("#search_text").val(search_text);
                changeButton();
            }
        });
    }

    let currentRow = {};//记录当前选中的数据
    //触发行单击事件
    layui.table.on('row(datalist)', function (obj) {
        //console.log(obj.tr) //得到当前行元素对象
        //console.log(obj.data) //得到当前行数据
        obj.tr.parent().find('tr').removeClass('active')
        obj.tr.addClass('active') //选中行加特殊背景颜色
        currentRow = obj.data;
        changeButton();
    });

    function changeButton() {
        let viewbtn = $("#viewbtn");
        let editbtn = $("#editbtn");
        let downbtn = $("#downbtn");
        let historybtn = $("#historybtn");
        let deletebtn = $("#deletebtn");
        deletebtn.addClass("layui-btn-disabled");
        J$("deletebtn").onclick = null;
        if (currentRow.sid) {
            viewbtn.removeClass("layui-btn-disabled");
            J$("viewbtn").onclick = viewFile;
            editbtn.removeClass("layui-btn-disabled");
            J$("editbtn").onclick = editFile;
            downbtn.removeClass("layui-btn-disabled");
            J$("downbtn").onclick = downloadFile;
            historybtn.removeClass("layui-btn-disabled");
            J$("historybtn").onclick = downloadHistory;
            if (currentRow.screatorid === tlv8.Context.getCurrentPersonID()) {
                deletebtn.removeClass("layui-btn-disabled");
                J$("deletebtn").onclick = deleteFile;
            }
        } else {
            viewbtn.addClass("layui-btn-disabled");
            J$("viewbtn").onclick = null;
            editbtn.addClass("layui-btn-disabled");
            J$("editbtn").onclick = null;
            downbtn.addClass("layui-btn-disabled");
            J$("downbtn").onclick = null;
            historybtn.addClass("layui-btn-disabled");
            J$("historybtn").onclick = null;
        }
    }

    function viewFile() {
        tlv8.viewFile(currentRow.sfileid, currentRow.sdocname);
    }

    function editFile() {
        tlv8.trangereditfile(currentRow.sfileid, currentRow.sdocname);
    }

    function downloadFile() {
        tlv8.downloadFile(currentRow.sfileid);
    }

    function downloadHistory() {

    }

    function deleteFile() {
        layui.layer.confirm("文件删除后不能恢复，确认删除吗？", function () {
            $.ajax({
                url: "/system/doc/file/" + currentRow.sfileid + "/delete/",
                type: "post",
                async: true,
                data: {docId: currenttreeNode.id},
                dataType: "json",
                success: function (re) {
                    if (re.state === true) {
                        layui.layer.msg("删除成功！");
                        doQuery();
                    } else {
                        layui.layer.alert("删除失败：" + re.msg);
                    }
                }
            });
        });
    }
</script>
</body>
</html>